﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using CodeIn.Diagnostics;
using CodeIn.Ui.Dock;
using System.Windows.Controls;
using System.Windows.Threading;
using CodeIn.Ui;
using CodeIn.Core.Modules;

namespace CodeIn.Modules.Misc.Dummy {
	public class DummyModule : BaseModule {
		private ContentControl myCC;

		protected override void InitializeOverride() {
		}

		protected override bool CanExecuteOverride(string[] args) {
			return true;
		}

		protected override void ExecuteOverride(string[] args) {
			var panel = UiHelper.CreatePanel("Dummy report", () => {
				myCC = new ContentControl();
				myCC.Content = new TextBlock() { Text = "Dummy execution in progress...\n" };
				return myCC;
			});

			UiHelper.ShowPanel(panel, PanelSide.TOPLEFT);

			int target = 2000;
			if (args.Length > 1)
				if (int.TryParse(args[1], out target))
					if (target < 100)
						target = 100;

			LocalTrace.WriteLine("Sleeping for " + target + " milliseconds !");

			for (int i = 0; i <= target; i++) {
				Thread.Sleep(1);
				int progress = i * 100 / target;
				if (i % (target * 20 / 100) == 0) {
					MessageHandlers.Trace.WriteLine("Progress = " + progress + "%");
					ReportProgress(progress);
				}
			}

			UiHelper.Synchronize(() => {
				(myCC.Content as TextBlock).Text += "Dummy execution done";
			});
		}
	}
}
